package com.example.shopinglist;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.ListAdapter;

import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private ListView myListView=null;
    private int icon=R.mipmap.ic_launcher;
    String[] name=new String[]{"table","phone","apple","cake","cup"};
    String[] price=new String[]{"$1880","$6880","$0.5","$2","$3"};
    private ImageView myImage=null;
    private TextView nameText,priceNumText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myListView=findViewById(R.id.listview);
        MyAdapter myAdapter=new MyAdapter();
        myListView.setAdapter(myAdapter);
    }

    private class MyAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return name.length;
        }

        @Override
        public Object getItem(int i) {
            return name[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            View itemView=View.inflate(MainActivity.this,R.layout.itemlayout,null);
            nameText=itemView.findViewById(R.id.name);
            priceNumText=itemView.findViewById(R.id.pricenum);
            myImage=itemView.findViewById(R.id.picture);
            nameText.setText(name[i]);
            priceNumText.setText(price[i]);
            myImage.setBackgroundResource(icon);
            return itemView;
        }
    }
}